package com.atguigu.tingshu.album.mapper;

import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.model.album.TrackStat;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumTrackListVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import com.atguigu.tingshu.vo.album.TrackStatMqVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface TrackInfoMapper extends BaseMapper<TrackInfo> {

    /**
     * 分页查询用户声音
     *
     * @param trackListVoPage
     * @param trackInfoQuery
     * @return
     */
    IPage<TrackListVo> selectUserTrackPage(Page<Object> trackListVoPage, @Param("vo") TrackInfoQuery trackInfoQuery);

    @Update("update track_info set order_num = order_num - 1 where album_id = #{albumId} and order_num > #{orderNum} ")
    void updateOrderNum(Long albumId, Integer orderNum);

    List<TrackStat> getStackstat(Long alubmId);

    /**
     * 根据专辑id查询声音列表
     * @param albumTrackListVoPage
     * @param albumId
     * @return
     */
    IPage<AlbumTrackListVo> selectAlbumTrackPage(Page<AlbumTrackListVo> albumTrackListVoPage, @Param("albumId") Long albumId);

    /**
     * 更新声音播放数
     * @param trackId
     * @param statType
     * @return
     */
    @Update("update track_stat set stat_num = stat_num + 1 where track_id = #{trackId} and stat_type = #{statType} and is_deleted = 0")
    int updateTrackStat(@Param("trackId") Long trackId, @Param("statType") String statType);



}
